package com.ijianji.module_play_video.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.LogUtils
import com.fenghuajueli.libbasecoreui.viewmodel.BaseViewModelActivity
import com.fenghuajueli.module_route.PlayVideoModuleRoute
import com.ijianji.module_play_video.R
import com.ijianji.module_play_video.databinding.ActivityFragmentContainerBinding
import com.ijianji.module_play_video.model.PlayVideoModel

@Route(path = PlayVideoModuleRoute.FRAGMENT_CONTAINER_ACTIVITY)
class FragmentContainerActivity : BaseViewModelActivity<PlayVideoModel, ActivityFragmentContainerBinding>() {

    val TYPE_VIDEO_LIST = 1000;
    val TYPE_VIDEO_COLLECTION = 1001;
    val TYPE_VIDEO_PLAY_HISTORY = 1002;

    @JvmField
    @Autowired(name = "type")
    var type: Int = -1

    var currentFragment: Fragment? = null


    override fun createViewModel(): PlayVideoModel {
        return PlayVideoModel()
    }

    override fun createViewBinding(): ActivityFragmentContainerBinding {
        return ActivityFragmentContainerBinding.inflate(layoutInflater)
    }

    override fun initView() {
        if (type == -1) {
            LogUtils.e("没有传入对应的类型-----------》$type")
            finish()
            return
        }
        when (type) {
            TYPE_VIDEO_LIST -> {
                currentFragment = ARouter.getInstance().build(PlayVideoModuleRoute.FRAGMENT_VIDEO_LIST).navigation() as Fragment
                binding.myActionBar.setTitle("视频列表")
            }
            TYPE_VIDEO_COLLECTION -> {
                currentFragment = ARouter.getInstance().build(PlayVideoModuleRoute.FRAGMENT_VIDEO_COLLECTION).navigation() as Fragment
                binding.myActionBar.setTitle("收藏列表")
            }
            TYPE_VIDEO_PLAY_HISTORY -> {
                currentFragment = ARouter.getInstance().build(PlayVideoModuleRoute.FRAGMENT_VIDEO_PLAY_HISTORY).navigation() as Fragment
                binding.myActionBar.setTitle("播放记录")
            }
            else -> {
                finish()
            }
        }
        currentFragment?.let {
            val tran = supportFragmentManager.beginTransaction()
            tran.replace(R.id.fragmentContainer, it)
            tran.commit()
        }
    }


}